﻿using AutoMapper;
using Inventory.API.Application.Command.ZonemanagementCommand;
using Inventory.Domain;
using Inventory.Errorcode.ErrorCode;
using Inventory.Infrastructure.Interfaces;
using MediatR;

namespace Inventory.API.Application.CommandHandler.ZonemanagementCommandHandler
{
    public class GeZonemanagementfoCommandHanlder : IRequestHandler<GeZonemanagementfoCommand, ApiResult<Zonemanagement>>
    {

        private readonly ILogger<GeZonemanagementfoCommandHanlder> _logger;

        private readonly IZonemanagementRepository repository;

        private readonly IMapper mapper;

        public GeZonemanagementfoCommandHanlder(ILogger<GeZonemanagementfoCommandHanlder> logger, IZonemanagementRepository repository, IMapper mapper)
        {
            _logger = logger;
            this.repository = repository;
            this.mapper = mapper;
        }
        public async Task<ApiResult<Zonemanagement>> Handle(GeZonemanagementfoCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var zonemanagement =await repository.GetAsync(x=>x.Zonemanagementid==request.Zonemanagementid);
                if (zonemanagement == null)
                {
                    return ApiResult<Zonemanagement>.Fail("未查到id", StatusCodeEnum.NotFound);
                }
                else
                {
                    return ApiResult<Zonemanagement>.Success(zonemanagement, StatusCodeEnum.Success);
                }
            
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, "Error in GeZonemanagementfoCommandHanlder");
             throw;
            }
        }
    }
}
